/*
** ADOBE SYSTEMS INCORPORATED
** Copyright 2012 Adobe Systems Incorporated
** All Rights Reserved.
**
** NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the
** terms of the Adobe license agreement accompanying it.  If you have received this file from a
** source other than Adobe, then your use, modification, or distribution of it requires the prior
** written permission of Adobe.
*/
package
{
    import sample.IntArrayLib.ram;
    
    import IntArrayLib;
    
    import sample.IntArrayLib.CModule;
    
    import flash.display.Sprite;
    import flash.text.TextField;
    
    public class Main extends Sprite
    {
        public function callCFunctions():void
        {
            var v:Vector.<int> = new Vector.<int>();
            v.push(1);
            v.push(2);
            v.push(3);
            v.push(4);
            v.push(5);
            
            // pass an ActionScript object in
            printLine("Sum: " + IntArrayLib.sumArray(v) + " == 15");
            printLine("Product: " + IntArrayLib.dotProductArray(v) + " == 120");
            
            // pass an ActionScript object in and get an ActionScript object returned
            var reversed:Vector.<int> = IntArrayLib.reverseArray(v); 
            printLine("Reversed: " + reversed + " == 5,4,3,2,1");
            
            var incremented:Vector.<int> = IntArrayLib.incrementArray(v) 
            printLine("Incremented: " + incremented + " == 2,3,4,5,6");
        }
        
        /** Constructor */
        public function Main()
        {
            CModule.startAsync(this);
            
            // setup the output text area
            output = new TextField();
            output.multiline = true;
            output.width = stage.stageWidth;
            output.height = stage.stageHeight;
            addChild(output);
            
            // start interacting with the C library
            callCFunctions();
        }
        
        private var output:TextField;
        private function printLine(string:String):void 
        {
            output.appendText(string + "\n");
            trace(string);
        }
    }
}
